package cac.fenjian.resource.common;

import cac.fenjian.resource.MsWpTool.dto.MsWpToolBasicDTO;
import com.cac.dme.adapter.rest.client.RestClient;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import com.cac.dme.core.context.RequestContextHolder;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Repository;


/**
 * @author unicoe
 */
@Repository
public class InvokeService {

    @Autowired
    RestClient restClient;

    /**
     * uri 调用uri
     * serviceName 调用的服务名
     * obj  参数
     * <p>
     * return String 响应
     * @return
     */
    public String callServicePost(String uri, String serviceName, Object obj) {
        HttpHeaders httpHeaders = new HttpHeaders();
        String xToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBcHDliY3nq6_mjojmnYMiLCJhdWQiOiIxIiwiQVBQX0lEIjoiMSIsIkxBTkdVQUdFX0NPREUiOiJ6aF9DTiIsIm5iZiI6MTU5NDEwOTI4NSwiaXNzIjoiQVZJQy1ESUdJVEFMIiwiZXhwIjozMTcxOTQ2MDk1LCJPUkdfSURFTlRJVFkiOiJPUkdfUk9PVCIsIlVTRVJfREVQVF9JRCI6IjEiLCJpYXQiOjE1OTQxMDkyODUsImp0aSI6IjY1MGFlNDU1LWE0OWEtNGVkYi1hODhlLThhODAwZGRmNmMwZiJ9.cL7yCcN04i3pCGCTsZ9gZMAhrX21kjQbAlX34RzPMXg";
        httpHeaders.add("X-Access-Token", xToken);
        httpHeaders.add("token", RequestContextHolder.getToken());
        ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {
        };
        String result = restClient.doPost(serviceName, uri, obj, typeReference, httpHeaders);
        return result;
    }

    /**
     * uri 调用uri
     * serviceName 调用的服务名
     * <p>
     * return String 响应
     */
    public String callServiceGet(String uri, String serviceName) {
        HttpHeaders httpHeaders = new HttpHeaders();
        String xToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBcHDliY3nq6_mjojmnYMiLCJhdWQiOiIxIiwiQVBQX0lEIjoiMSIsIkxBTkdVQUdFX0NPREUiOiJ6aF9DTiIsIm5iZiI6MTU5NDEwOTI4NSwiaXNzIjoiQVZJQy1ESUdJVEFMIiwiZXhwIjozMTcxOTQ2MDk1LCJPUkdfSURFTlRJVFkiOiJPUkdfUk9PVCIsIlVTRVJfREVQVF9JRCI6IjEiLCJpYXQiOjE1OTQxMDkyODUsImp0aSI6IjY1MGFlNDU1LWE0OWEtNGVkYi1hODhlLThhODAwZGRmNmMwZiJ9.cL7yCcN04i3pCGCTsZ9gZMAhrX21kjQbAlX34RzPMXg";
        httpHeaders.add("X-Access-Token", xToken);
        httpHeaders.add("token", RequestContextHolder.getToken());
        ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {
        };
        String result = restClient.doGet(serviceName, uri, typeReference, httpHeaders);
        return result;
    }
}
